package com.car.carmgr.service.impl;

import com.car.carmgr.bean.Menu;
import com.car.carmgr.bean.Role;
import com.car.carmgr.mapper.RoleMapper;
import com.car.carmgr.service.RoleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public int insert(Role role) {
        return roleMapper.insert(role);
    }

    @Override
    public int deleteRoleById(Integer roleId) {
        return roleMapper.deleteRoleById(roleId);
    }

    @Override
    public int updateRole(Role role) {
        return roleMapper.updateRole(role);
    }

    @Override
    public Role selectById(Integer roleId) {
        return roleMapper.selectById(roleId);
    }

    @Override
    public PageInfo<Role> findRoleByWhere(String roleName,String roleDesc,Integer page,Integer limit) {
        PageHelper.startPage(page,limit);
        List<Role> list = roleMapper.findRoleByWhere(roleName,roleDesc);
        PageInfo<Role> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public Integer getCountByWhere(String roleName,String roleDesc) {
        return roleMapper.getCountByWhere(roleName,roleDesc);
    }

    @Override
    public int updRoleMenuByRoleId(Integer roleId, Integer[] arr) {
        int i =roleMapper.deleteRoleMenuByRoleId(roleId);
        int j =roleMapper.insRoleMenuByRoleId(roleId,arr);
        return i+j;
    }

    @Override
    public List<Role> findAll() {
        return roleMapper.findAll();
    }

    @Override
    public List<Role> findRoleByUserId(Integer userId) {
        return roleMapper.findRoleByUserId(userId);
    }
}
